DPWorkerThread now sets up a coroutine stack.
[hom.git] / Tests / Unit Tests / DPCoroutineMultiThreadTests.m
blobef85fba53dc0ec33f61cfd2b5aacd9012c3b3c49
1 //
2 //  DPCoroutineMultiThreadTests.m
3 //  HigherOrderMessaging
4 //
5 //  Created by Ofri Wolfus on 03/08/07.
6 //  Copyright 2007 Ofri Wolfus. All rights reserved.
7 //
9 #import "DPCoroutineMultiThreadTests.h"
10 #import "DPCoroutine.h"
13 @implementation DPCoroutineMultiThreadTests
15 - (unsigned)numberOfIterations {
16         return 50;
19 - (void)incByOne {
20         while (OSAtomicIncrement32Barrier(&count) < 5) {
21                 DPCoroutineYield();
22         }
25 - (void)checkCompletion {
26         int32_t c = count;
27         OSMemoryBarrier();
28         
29         while (c < 5) {
30                 DPCoroutineYield();
31                 OSMemoryBarrier();
32                 c = count;
33         }
34         
35         [pool release];
36         [self setStatus:YES forPendingTest:@"testMultiThreaded"];
39 - (void)generateJobs {
40         [pool sendCoroutineMessage:MSG(incByOne)
41                                                         to:self];
42         [pool spawnThread];
43         [pool spawnThread];
44         
45         [pool sendCoroutineMessage:MSG(checkCompletion)
46                                                         to:self];
47         
50 - (void)testMultiThreaded {
51         count = 0;
52         pool = [[DPThreadPool alloc] init];
53         
54         // Let UITestingKit mark us as a pending test.
55         // Yes, its a bug but I'm not feeling like fixing it right now.
56         [self receiveMessage:MSG(generateJobs)
57                           afterDelay:0.1];
60 @end